<?php
$current_page = "index";
header("Content-Type: text/html; charset=utf-8");

$page = 1;
$result_page = 20;

if (isset($_REQUEST['page'])) {
    $page = $_REQUEST['page'];
}

$jsonurl = "http://nibble.li/twittertido/web/getHomePagination.php?page=$page";
$json = file_get_contents($jsonurl, 0, null, null);
$json_output = json_decode($json, true);
$arrays = $json_output['tweets'];

$totalurl = "http://nibble.li/twittertido/web/getInfo.php?field=total";
$total = file_get_contents($totalurl, 0, null, null);
?>
<?php include_once("detect.php"); ?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Twittertido - Procastination everywhere!!!</title>
        <meta property="og:title" content="Twittertido - Procastination everywhere!!!" />
        <meta property="og:type" content="website" />
        <meta property="og:url" content="http://twittertido.com.es" />
        <meta property="og:image" content="http://twittertido.com.es/img/logo_header.png" />
        <link rel="stylesheet" href="css/glamour.css" />
        <script src="js/jquery-1.6.2.min.js"></script>
        <script src="js/common.js"></script>
        <script type="text/javascript">
            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'UA-28972217-1']);
            _gaq.push(['_trackPageview']);

            (function() {
                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
            })();
        </script>
    </head>
    <body>
        <?php include_once("header.php"); ?>
        <div class="wrapper">
            <div class="content">
                <div class="tweets">
                    <?php $i = -1;
                    foreach ($arrays as $tweet) { ?>
                        <?php $i++;
                        if ($i == 10) { ?>
                            <script type="text/javascript"><!--
                                google_ad_client = "ca-pub-4013617504060877";
                                /* Twittertido Desktop */
                                google_ad_slot = "7224782497";
                                google_ad_width = 468;
                                google_ad_height = 60;
                                //-->
                            </script>
                            <script type="text/javascript"
                                    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
                            </script>
                        <?php } ?>
                        <?php
                        $aux = $i % 10;
                        if ($aux > 0) {
                            $class = "bg_$aux";
                        } else {
                            $class = "";
                        }
                        ?>
                        <div class="wrapper_tweet <?php print $class; ?>">
                        <!--a name="fb_share" share_url="http://twittertido.com.es/desktop/tweet.php?id=<?php print $tweet['id'] ?>"></a>
                        <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://twittertido.com.es/desktop/tweet.php?id=<?php print $tweet['id'] ?>" data-text="Visita este sitio" data-via="twittertido" data-lang="es"></a>
                        <g:plusone size="small" href="http://twittertido.com.es/desktop/tweet.php?id=<?php print $tweet['id'] ?>"></g:plusone-->
                            <div class="tweet">
                                <table>
                                    <tr>
                                        <td class="avatar">
                                            <img src="https://api.twitter.com/1/users/profile_image?screen_name=<?php print $tweet['user_tweet']; ?>&size=normal" />
                                        </td>
                                        <td style="padding-left: 10px;">
                                            <a href="tweet.php?id=<?php print $tweet['id'] ?>" class="link">
                                                <div class="title"><?php print $tweet['user_tweet'];
                        ?></div>
                                                <div><?php print $tweet['tweet']; ?></div>
                                            </a>
                                        </td>
                                    </tr>
                                </table>
                                <table class="tweet_actions">
                                    <tr>
                                        <td>
                                            <div class="fl mlfive pointer" onclick="like(<?php print $tweet['id']; ?>)">
                                                <img id="ic_like_<?php print $tweet['id']; ?>" src="img/ic_like.png" />
                                            </div>
                                            <div class="fl mlfive pointer" onclick="dislike(<?php print $tweet['id']; ?>)">
                                                <img id="ic_dislike_<?php print $tweet['id']; ?>" src="img/ic_dislike.png" />
                                            </div>
                                        </td>
                                        <td>
                                            <div class="fr mrfive pointer">
                                                <a href="tweet.php?id=<?php print $tweet['id'] ?>"><img src="img/ic_action_comments.png" /></a>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div class="clear"></div>
                            <div>

                            </div>
                        </div>
                    <?php } ?>
                </div>
                <?php if ($page > 1) { ?>
                    <a class="button" id="link_previous" href="index.php?page=<?php print $page - 1 ?>">
                        Anterior
                    </a>
                <?php } ?>
                <?php if (($total / $result_page) > $page) { ?>
                    <a class="button" id="link_next" href="index.php?page=<?php print $page + 1 ?>">
                        Siguiente
                    </a>
                <?php } ?>
                <div class="clear"></div>
            </div>
        </div>

    </body>
</html>
